<?php

/**
 * consultation actions.
 *
 * @package    app_clinique
 * @subpackage consultation
 * @author     Your name here
 * @version    SVN: $Id: actions.class.php 2288 2006-10-02 15:22:13Z fabien $
 */
class consultationActions extends autoconsultationActions
{

    public function executeCreateConsultation(){

         $this->sf_consultation = $this->getsfConsultationOrCreate();
         $idpatient = $this->getRequestParameter('idpatient');
         $this->patient = sfPatientPeer::retrieveByPk($idpatient);

         if ($this->getRequest()->getMethod() == sfRequest::POST){

                $this->updatesfConsultationFromRequest();
                $this->savesfConsultation($this->sf_consultation);
                $this->setFlash('notice', 'Your modifications have been saved');

                return $this->redirect('patient/show?id='.$this->sf_consultation->getPatientId());
                
         }
         else
         {
              $this->labels = $this->getLabels();
         }

    }

  public function handleErrorCreateConsultation()
  {
    $this->preExecute();
    $this->sf_consultation = $this->getsfConsultationOrCreate();
    //$idpatient = $this->getRequestParameter('idpatient');

    //$this->patient = sfPatientPeer::retrieveByPk($idpatient);
    $this->updatesfConsultationFromRequest();
    
    $this->labels = $this->getLabels();
    $this->getRequest()->setError("erreur", "mais quel erreur");
    $this->redirect('consultation/createConsultation?erreur=1&idpatient='.$this->sf_consultation->getPatientId());

  }

  public function executeEdit()
  {
    $this->sf_consultation = $this->getsfConsultationOrCreate();

    if ($this->getRequest()->getMethod() == sfRequest::POST)
    {
      $this->updatesfConsultationFromRequest();

      $this->savesfConsultation($this->sf_consultation);

      $this->setFlash('notice', "L'enregistrement a été effectué");

      if ($this->getRequestParameter('save_and_add'))
      {
        return $this->redirect('consultation/create');
      }
      else if ($this->getRequestParameter('save_and_list'))
      {
        return $this->redirect('consultation/list');
      }
      else
      {
        return $this->redirect('consultation/edit?id='.$this->sf_consultation->getId());
      }
    }
    else
    {
      $this->labels = $this->getLabels();
    }
  }
}
